﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ESRI.ArcGIS.Carto;

namespace MyGIS.Forms
{
    public partial class RenderForm : Form
    {
        public ILayer SelectedLayer { get; private set; }
        public string NewLayerName { get; private set; } // 添加的公共属性

        public RenderForm(IMap map)
        {
            InitializeComponent();
            LoadRasterLayers(map);
        }

        private void LoadRasterLayers(IMap map)
        {
            cmbLayers.Items.Clear();

            for (int i = 0; i < map.LayerCount; i++)
            {
                var layer = map.get_Layer(i);
                if (layer is IRasterLayer)
                {
                    cmbLayers.Items.Add(new LayerItem(layer));
                }
            }

            cmbLayers.SelectedIndex = cmbLayers.Items.Count > 0 ? 0 : -1;
        }


        private void InputGrid_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (cmbLayers.SelectedItem == null || string.IsNullOrWhiteSpace(txtLayerName.Text))
            {
                MessageBox.Show("请选择图层并输入新图层名称！");
                return;
            }

            SelectedLayer = ((LayerItem)cmbLayers.SelectedItem).Layer;
            NewLayerName = txtLayerName.Text; // 设置属性值
            DialogResult = DialogResult.OK;
            Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }
        // 辅助类用于在下拉框中显示图层名称
        private class LayerItem
        {
            public ILayer Layer { get; }
            public string Name => Layer.Name;
            public LayerItem(ILayer layer) => Layer = layer;
            public override string ToString() => Name;
        }

        
    }
}
